import static spark.Spark.*;
import spark.Request;
import spark.Response;
import spark.Route;
import spark.template.freemarker.FreeMarkerRoute;
import controllers.*;

public class Routes {
	public void init(){
		
	    get(new FreeMarkerRoute("/") {
	          @Override
	          public Object handle(Request request, Response response) {
	             return new HomeController(request, response).home();
	          }
	    });
		
		/********************************************************************/
		/**************************** Auth  *********************************/
		
		get(new FreeMarkerRoute("/login"){
			@Override
			public Object handle(Request request, Response response) {
				return new AuthController(request, response).login();
			}
		});
		
		get(new FreeMarkerRoute("/logout"){
			@Override
			public Object handle(Request request, Response response) {
				return new AuthController(request, response).logoff();
			}
		});
		
		post(new FreeMarkerRoute("/login"){
			@Override
			public Object handle(Request request, Response response) {
				return new AuthController(request, response).login();
			}
		});
		
		/********************************************************************/
		/**************************** Report ********************************/
		get(new FreeMarkerRoute("/report/student"){
			@Override
			public Object handle(Request request, Response response) {
				return new ReportController(request, response).generateIndividualReport();
			}
		});
		
		post(new FreeMarkerRoute("/report/student"){
			@Override
			public Object handle(Request request, Response response) {
				return new ReportController(request, response).generateIndividualReport();
			}
		});
		
		get(new FreeMarkerRoute("/report/course"){
			@Override
			public Object handle(Request request, Response response) {
				return new ReportController(request, response).calculateCourseAttendantRate();
			}
		});
		
		post(new FreeMarkerRoute("/report/course"){
			@Override
			public Object handle(Request request, Response response) {
				return new ReportController(request, response).calculateCourseAttendantRate();
			}
		});
		
		/********************************************************************/
		/**************************** Student *******************************/
		get(new FreeMarkerRoute("/student"){
			@Override
			public Object handle(Request request, Response response) {
				return new StudentController(request, response).view();
			}
		});
		/********************************************************************/
		/**************************** Permits *******************************/
		get(new FreeMarkerRoute("/permits"){
			@Override
			public Object handle(Request request, Response response) {
				return new PermitController(request, response).list();
			}
		});
		
		get(new FreeMarkerRoute("/permits/:id"){
			@Override
			public Object handle(Request request, Response response) {
				return new PermitController(request, response).view();
			}
		});
		
		get(new FreeMarkerRoute("/permits/add"){
			@Override
			public Object handle(Request request, Response response) {
				return new PermitController(request, response).add();
			}
		});
		
		post(new Route("/permits/add"){
			@Override
			public Object handle(Request request, Response response) {
				return new PermitController(request, response).add();
			}
		});
		
		/********************************************************************/
		/**************************** Tasks *********************************/
		get(new FreeMarkerRoute("/tasks"){
			@Override
			public Object handle(Request request, Response response) {
				return new TaskController(request, response).list();
			}
		});
		
		get(new Route("/tasks/delete/:id"){
			@Override
			public Object handle(Request request, Response response) {
				return new TaskController(request, response).delete();
			}
		});
		
		get(new FreeMarkerRoute("/tasks/edit/:id"){
			@Override
			public Object handle(Request request, Response response) {
				return new TaskController(request, response).edit();
			}
		});
		
		get(new FreeMarkerRoute("/tasks/add"){
			@Override
			public Object handle(Request request, Response response) {
				return new TaskController(request, response).add();
			}
		});
		
		post(new FreeMarkerRoute("/tasks/edit/:id"){
			@Override
			public Object handle(Request request, Response response) {
				return new TaskController(request, response).edit();
			}
		});
		
		post(new Route("/tasks/add"){
			@Override
			public Object handle(Request request, Response response) {
				return new TaskController(request, response).add();
			}
		});
		
		/********************************************************************/
		/*************************** Attendants *****************************/
		get(new FreeMarkerRoute("/attendants"){
			@Override
			public Object handle(Request request, Response response) {
				return new AttendantController(request, response).list();
			}
		});
		
		post(new FreeMarkerRoute("/attendants"){
			@Override
			public Object handle(Request request, Response response) {
				return new AttendantController(request, response).list();
			}
		});
		
		get(new FreeMarkerRoute("/attendants/:courseId/:sessionId"){
			@Override
			public Object handle(Request request, Response response) {
				return new AttendantController(request, response).manageSessionAttendants();
			}
		});
		
		post(new FreeMarkerRoute("/attendants/:courseId/:sessionId"){
			@Override
			public Object handle(Request request, Response response) {
				return new AttendantController(request, response).manageSessionAttendants();
			}
		});
		
		get(new FreeMarkerRoute("/attendants/:courseId/:sessionId/generaterecord"){
			@Override
			public Object handle(Request request, Response response) {
				return new AttendantController(request, response).generateAttendantRecords();
			}
		});
		
		/********************************************************************/
		/**************************** Courses *******************************/
		get(new FreeMarkerRoute("/courses"){
			@Override
			public Object handle(Request request, Response response) {
				return new CourseController(request, response).list();
			}
		});
		
		get(new FreeMarkerRoute("/courses/:id"){
			@Override
			public Object handle(Request request, Response response) {
				return new CourseController(request, response).get();
			}
		});
		
		get(new Route("/courses/:id/json_tutors"){
			@Override
			public Object handle(Request request, Response response) {
				return new CourseController(request, response).getTutors();
			}
		});
		
		get(new Route("/courses/:id/json_lecturers"){
			@Override
			public Object handle(Request request, Response response) {
				return new CourseController(request, response).getLecturers();
			}
		});
		
		get(new FreeMarkerRoute("/courses/:id/teachers"){
			@Override
			public Object handle(Request request, Response response) {
				return new CourseController(request, response).listTeachers();
			}
		});
		
		get(new FreeMarkerRoute("/courses/:id/students"){
			@Override
			public Object handle(Request request, Response response) {
				return new CourseController(request, response).listStudents();
			}
		});
		
		get(new FreeMarkerRoute("/courses/:id/:tutorId/:tutorName"){
			@Override
			public Object handle(Request request, Response response) {
				return new CourseController(request, response).manageStudentsByTutor();
			}
		});
		
		post(new FreeMarkerRoute("/courses/:id/:tutorId/:tutorName"){
			@Override
			public Object handle(Request request, Response response) {
				return new CourseController(request, response).manageStudentsByTutor();
			}
		});
		
		
		get(new FreeMarkerRoute("/courses/:id/sessions"){
			@Override
			public Object handle(Request request, Response response) {
				return new CourseController(request, response).listSessions();
			}
		});
		
		get(new FreeMarkerRoute("/courses/:id/addsession"){
			@Override
			public Object handle(Request request, Response response) {
				return new CourseController(request, response).addTeachingSession();
			}
		});
		
		post(new FreeMarkerRoute("/courses/:id/addsession"){
			@Override
			public Object handle(Request request, Response response) {
				return new CourseController(request, response).addTeachingSession();
			}
		});
	}
}